using System;
using System.Collections.Generic;
using System.Text;
using SlimDX;
using Barrage.Global;

using Barrage.Elements.Cameras;

namespace Barrage.Scenes
{
    /// <summary>
    /// Borders of a 2D Screen for Scene2D Calculations
    /// </summary>
    public enum GUIBorders{
        /// <summary>
        /// Bottom left screen corner
        /// </summary>
        BottomLeft,
        /// <summary>
        /// Bottom right screen corner
        /// </summary>
        BottomRight,
        /// <summary>
        /// Top left screen corner
        /// </summary>
        TopLeft,
        /// <summary>
        /// Top right screen corner
        /// </summary>
        TopRight
    }
    /// <summary>
    /// Simply a Scene with an Ortho 2D Projection camera
    /// Also it has two functions to easen item positioning on 2D Coordinates
    /// </summary>
    public class Scene2D : Scene
    {
        /// <summary>
        /// Inits a 2D Scene (With an ortho 2D Projection camera)
        /// </summary>
        public Scene2D()
        {
            Camera = new Scene2DCamera();
        }

        /// <summary>
        /// Returns the absolute screen position from a relative one
        /// </summary>
        /// <param name="relPos">Relative screen position, ranging from [-1,-1] to [1,1]</param>
        /// <returns>Absolute screen position in pixels</returns>
        public Vector2 GUIPosition(Vector2 relPos)
        {
            return Scene2DCamera.GUIPosition(relPos);
        }


        /// <summary>
        /// Returns an absolute screen position for a sized element so it has the specified margin to the screen border
        /// </summary>
        /// <param name="border">Screen corner from which the calculations should be done</param>
        /// <param name="desiredMargin">Desired margin to screen border in pixels</param>
        /// <param name="pixelSize">Size of the element in pixels</param>
        /// <returns>The final absolute position of the element</returns>
        public Vector2 GUIPosition(GUIBorders border, Vector2 desiredMargin, Vector2 pixelSize)
        {
            Vector2 relSize = new Vector2(pixelSize.X / Engine.DefaultRenderTargetDescription.Width,pixelSize.Y / Engine.DefaultRenderTargetDescription.Height);
            Vector2 centeredPos = relSize + desiredMargin;
            switch (border)
            {
                case GUIBorders.TopLeft:
                    return GUIPosition(new Vector2(-1+centeredPos.X, 1 - centeredPos.Y));
                case GUIBorders.TopRight:
                    return GUIPosition(new Vector2(1-centeredPos.X, 1 - centeredPos.Y));
                case GUIBorders.BottomLeft:
                    return GUIPosition(new Vector2(-1 + centeredPos.X, -1 + centeredPos.Y));
                case GUIBorders.BottomRight:
                    return GUIPosition(new Vector2(1 - centeredPos.X, -1 + centeredPos.Y));
            }
            return Vector2.Zero;
        }
    }
}
